package com.sigerap.ticket.model.dao.jpa;

import java.util.List;




import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.sigerap.ticket.model.Ticket;
import com.sigerap.ticket.model.dao.TicketDAO;
/**
 * 
 * @author Spirit-20121
 *
 */
public class JPATicketDAO implements TicketDAO {

	private EntityManager em;
	private Ticket ticket;

	public JPATicketDAO(EntityManager em) {
		this.em = em;
	}

	@Override
	public List<Ticket> findAll() {
		Query query = em.createQuery("Select p.numero From Ticket p");
		return query.getResultList();
	}
	
	@Override
	public Ticket findByNumero(Ticket p){
		ticket=em.find(Ticket.class, p.getNumero());
		return ticket;
	}

	@Override
	public Ticket findByNombre(int numero) {
		ticket = (Ticket) em
				.createQuery(
						"Select p from Ticketr p where p.numero =: numero")
				.setParameter("numero", numero).getSingleResult();
		;
		return ticket;
	}

	@Override
	public Ticket insert(Ticket p) {
		// TODO Auto-generated method stub
		em.persist(p);
		return p;
	}

}
